﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CalcTriangleWpf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {       //try catch 异常处理
                float a, b, c, p;
                double s;

                a = float.Parse(tbA.Text);
                b = float.Parse(tbB.Text);
                c = float.Parse(tbC.Text);

                //先要有abc的值才能算p
                p = (a + b + c) / 2;

                //先要有 a b c p 的值才能算s
                s = Math.Sqrt(p * (p - a) * (p - b) * (p - c));

                //输出 s
                tbResult.Text = "面积：" + s;
            }
            catch (Exception ex)
            {
                MessageBox.Show("输入有误，请输入数字。\n"+ex.Message);
            }
        }
    }
}
